from random import Random
def inverse_right(res, shift, bits=32):
    tmp = res
    for i in range(bits // shift):
        tmp = res ^ tmp >> shift
    return tmp

def inverse_left_mask(res, shift, mask, bits=32):
    tmp = res
    for i in range(bits // shift):
        tmp = res ^ tmp << shift & mask
    return tmp

def inv_extract_number(y):
    y = inverse_right(y, 18)
    y = inverse_left_mask(y, 15, 4022730752)
    y = inverse_left_mask(y, 7, 2636928640)
    y = inverse_right(y, 11)
    return y & 0xffffffff

def recover_mt(record):
    """
    恢复624个state，即可预测后面的随机数
    :param record: 624个随机数
    :return:
    """
    state = [inv_extract_number(i) for i in record][:624]
    gen = Random()
    gen.setstate((3, tuple(state + [0]), None))
    return gen

s = 0x24d27d3661e5b176ffe988cfc8b450a3268c5ea4b28d4b8cfdd11f8150f43d1283c3be3eb37d51205314c0cb21086954c66a082d10680b1f0c80153085d104a8bf5fddd527b375ed301b371a860c0244ef800c16fbb11de548e93c03455b35d697ce4795795fb91158fc05b8bf5e51274c4b8c3c4b637680866c7bec0dd35dd5e7796ea6e9380adff2a062392f9dbe43045f7ff488de52a0d3a75555783adb1d4e163dc45c66d0955276cbababe086ca8de4a36c02db5d8dfd62b4ebdcf5a25f4f8af8b1689dcb27d46b6ea47bee7dfe3658887e2df74d736bf001c11b887eea11dd39b5c92dcefd57926b42b6491bfe1f665aa922f9821af41d81f1639abbbc2569f9e639b041d0a247bdc35303b67f5834d8a8decb1c7b4ff204b1b5ab6401e2f7341ecc5ba058d352657e3704c629f891b04aae1041bbadbcfc9a6762f36968f302f401b40953f72be4384eb5e528308f3e7239691fef7a201adfc08cef33e9f1c6896817211e31b65283db701c74467055fa9a2c1fd1dcc8abe940b632b5321edc15108f8978a8f1e5af1af3fd3af1c54c61250a735c793afd7d0cc7b253342d2947fcab6b6dfa880e6cffed951694f335bd2e89ed1dc3890bc6e405cbef3a0c8d585abb568599dc302a0f93e7802b68c9e70787fb237d77e4a956f76b41a624d87316910a8f970a57d8cf2eb8c03718cb4491bc9bbc8ac9b7bfead2cf22cb5cff008a7b7265818940459021ae5757b736633de067b0708fcff238ead9b45d39eda88c58fa017b8845d7577dc0a820453f046f692565559dab575b4822f31ae21be5bb9375cb0957a19459be1478ad9cee281fc2434c60b1cebda433f5e1abd36a227b7ca87aa8c006c45e0df6a905d5d0ff6582d2623ef960b08d55e86c177c4ec1bd6f8a8d7acf9e61b8dfcce27c71fb1a3e02d256b23ca0f89300d893b87388a5a2766d779100b7d968fd46fcd3b6f712ea022779ab8930ef89021ddd07a085840ddace7ae97f6365929be9085329d085cd15583fd8d903901e7bd3632cdf06d8f10ac6e52935122fc775c6dced5fa920a6ad15b81f47bac2213c2f14215ca5e4ce406f74ecfca42906ece181b441c077052e0dc8cae6230765a5a944254b236fff03fc4a52c85878da88630e59a30e8e6ec1a837147e39e06d7c8bcc08046a88c63728eb3564ff89c214fb1814405a64881790e2c27402ce7bc97998780572ed886015063297ed2c3b4728d7a59b6a45d98cbb1de5b368ce71d220fa0c31a3baedc0b0916026209d7ef0e5354c7cedc5d0e7f815824fdbd556f3cb4c4b714b814d01f7543c234f40cf593709286c1f7a905d17a2e54d0283aacdc94abae1c9be60951de702d4738c3c2c348b0b48ec00f130aa8859b347a62a92bc4649b4d2b07296399f6990cc046d7d3de78678889daee3bde11fb8c2a4c995ea1d3025ab3170b9d29a63b5ab55b9d57e22f0e92e449bae74022f5fcf84bd339c62940f9f9ce0cf5f57d3c11e7a1e2f527ffc396b467070cfb34d46ce0288485f59ffe0655263c22895771496b6b5c509f04e4bc4c771693e2d64c32c0b019b3e614d80122cd09511224c80ae351d05cb51bad0f4e5c46bdfa83fc54117910ec99f71fb16aa0f67d14955010bb3540152a9dd4ae7b1ab39959295fc12fe893667dce8f8611955f8f05e6e9be109a75b1621a2d6dc3c1d794771e80888356df177b69ea532b6e6d55eac3ff5fc004c032122dd867f935c9469fb2810ce8d9694d50e45ddce1dfa85171f124e6729fbeb5b9a03782105b8c94c6be0327fd0e23e8f352c775d5caa2ecd443cfe332f80078ce9a90ac248b7977c113fdb6585539c526c006bfeca98a39fe91d41b3fb6106b127aac11231080c4d1eddbae46bc673e36b74d63608fab5bb8387ea55952d2af7f0c12a13c11ceb32bc11a1bfc0c35afff7dfda4f4a9f95d25964d0653d929031ddb9dbfda5a598bacbbd43005eb88317818278c133af85804521a356a3c56f6d0a653426864feec138c40dde1ef191428a5dafb923835b59227ce84357019e56a99e9402e8ff69d77931d5f872479ad9caa65bc30a05b5e662e7d67718055a4ecc6bfe8d696a0b62c59f0a027e847de32f78f0beb0bdb2382d608e6d30f4a63c709559faa603032dea3947de152cf0dd0d6817b6e4e1451c8fe03f23da949050a25ceafa541bd30f19075fff45d54a85dbd483c3a36a78406dac95cd7cf5acbb34fb2c3af55b64c413637d56909a612a2927d9286af3f3e27938f93f407465bf7675374c8b872be8ac68881ea72d48b2673e63d83c6dfed664e9daf4cb5d313d7e0b1bd18f3a348c7d3583d298abe778dec36db9e8266f7b9c59dcd8e3c41fc3b90bfb7c5bb5840f5b782ffa4eaea7ae16b42e3340882e6776d2f6898370e7fa132a23da0e600a15d0cce1730683eb297b9a82861704ecdfeeebc7b71df59dd48e03b4ff7da01b98a96c6b8d63611810501207f1c41d7c2ab980b323e2099154abfb07e844d7dc69b2870f98ac4c47f83e7fab83e2ce2bf36aaf61972c92afa01d8d001a24d0a8060824b2b85da1e6f90540daf0aa00517e819962a1d51a06660af263648eca5847d19ccee0f553e06bb8c368760a9de33d39cc81f4edb731fc5b773e38bb4f0e713c6151626e3e13e0e0849efa733f27e97835782acb32e6fc41cf53c63100d1eafff8054a6a9ebc5eb5c4b667a0ebfb14594fc76be216def690d5c75638cdcc9c70c0b43b2c3bcfd5137f033806b801c6c50024e4a6e55447fb1579234be15784af25b57c2ee67cfe0f4af67dd3666adb9616a6fc9785edeaf6f15daf251d48a7c2a9b3e8fd7401738a0a4aee2cd8fa61da453bb68aa1c83abe6566de6ec274a08fd4aa0a9254c2ff78ed8af39ae9dcd0b68e4a4a5ae63ef84a2b8db3fcda2bb5301848c9aaa7bc911da7bbe0ec94792f7e400e7e1c73b88d8149965a8a452379b83cb0037771c953b397dd11118158e30c3b8c9d52e16bff7833dd5c1e3e6727e1109f73f1a36b33d072bfb8afdfe04becc7d2fdc9df3802a1500ded4d44525635231273a3d96596f503887e2f21a47fe19cb4c7f05323d60b684b78e39e3df1e762c12c633b06d228db8eb559caeba475de4b381141adb822ebaf736c0092f15e94fd3b12f839e1c642f1b2ae0d2f2e0e52d8a5813a66878cb0172a4aa5283770a151a3ab6e3231657e52dbc5da13ce433b330de70147948e3435e759c9540349d5d044d044f450218311cfbf3e97a24e9848c7cb83558e488006f1baf17bc4e817ac834edf12115102196fe0a87e092005a6c6ed3a9dbf4787d35c287af2de9e13b223b0b8cd45f08c9ef843ac681968114db6cf78aa358e7efc494738cb5b7ddedc4aaf4e071a664178c15f12e6e85a5fc9876b5b82c3e5be76266a78019c6327dcfe61246b5894ade148deaf24d63ff45e4e9ff656cfd28282a989c0b06ca4fd37d801abfff4b37da2eb6a1a6949fa5994a75bddaaddb561477ab3dfc0bda9ac90a03c938f3274 # 随机数
ss = []
for i in range(624):
    ss.append(s & 0xffffffff)
    s >>= 32

mt = recover_mt(ss)
mt.getrandbits(624*32)
print(mt.getrandbits(32)) # 2866792166